home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Files / Delete_Current.bsh < prev    next >
Encoding:
Text File  |  2004-08-29  |  1.5 KB  |  76 lines

  1. /*
  2.  * Delete_Current.bsh - Deletes the current
  3.  * buffer's file on disk, but doesn't close 
  4.  * the buffer.
  5.  *
  6.  * Copyright (C) 2003-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
  7.  *
  8.  * $Id: Delete_Current.bsh,v 1.1 2004/03/19 15:57:59 spestov Exp $
  9.  */
  10.  
  11. import javax.swing.SwingUtilities;
  12. import org.gjt.sp.jedit.io.*;
  13.  
  14.  
  15. BufferStatusChecker(View view){
  16.     run(){
  17.         jEdit.checkBufferStatus(view);
  18.     }
  19.     return this;
  20. }
  21.  
  22.  
  23. void deleteCurrentBuffer(View view){
  24.     Buffer buffer = view.getBuffer();
  25.  
  26.     // don't bother deleting new buffers (don't exist on disk)
  27.     if(buffer.isNewFile()){
  28.         Macros.error(view, "Buffer doesn't exist on disk.");
  29.         return;
  30.     }
  31.  
  32.     try{
  33.         String path = buffer.getPath();
  34.         VFS vfs = VFSManager.getVFSForPath(path);
  35.         int caps = vfs.getCapabilities();
  36.         int del = VFS.DELETE_CAP;
  37.         int res = caps & del;
  38.         if(res == 0){
  39.             Macros.error(view, "VFS " + vfs.getName() 
  40.                          + " doesn't support deleting.");
  41.             return;
  42.         }
  43.     
  44.         Object session = null;
  45.         try{
  46.             session = vfs.createVFSSession(path,view);
  47.             if(vfs._delete(session,path,view)){
  48.                 view.getStatus().setMessageAndClear("Deleted: " + path);
  49.             }
  50.             // invoke buffer status check
  51.             SwingUtilities.invokeLater(BufferStatusChecker(view));
  52.         }
  53.         finally{
  54.             if(session != null)
  55.                 vfs._endVFSSession(session,view);
  56.         }
  57.     }
  58.     catch(Exception e){
  59.         Macros.error(view, e.toString());
  60.     }
  61. }
  62.  
  63. deleteCurrentBuffer(view);
  64.  
  65. /*
  66.  
  67.     <listitem>
  68.         <para><filename>Delete_Current.bsh</filename></para>
  69.         <abstract><para>
  70.         Deletes the current buffer's file on disk, but 
  71.         doesn't close the buffer.
  72.         </para></abstract>
  73.     </listitem>
  74.  
  75. */
  76.